﻿using DHQGHN.DAL.Base;
using DHQGHN.DAL.Common;
using DHQGHN.DAL.Models.DHQG;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DHQGHN.DAL.DAO.DHQG
{
    public class ShareFileDAO : SqlDAO
    {
        public ShareFileDAO(string connectionString, System.Type type = null) :
            base(connectionString, type) { ;}

        public const string PROCEDURE_INSERT = "spShareFile_Insert";
        public const string PROCEDURE_UPDATE = "spShareFile_Update";
        public const string PROCEDURE_SEARCH_BY_DON_VI = "spShareFile_SearchByDonviID";
        public const string PROCEDURE_SEARCH_BY_ID = "spShareFile_SearchByID";
        public const string PROCEDURE_SEARCH_BY_DON_VI_TRUY_CAP = "spShareFile_SearchByDonViTruyCap";
        public const string PARAM_SO_VAN_BAN = "@SO_VAN_BAN";
        public const string PARAM_DELETED = "@DELETED";
        public const string PARAM_VAN_BAN_ID = "@VAN_BAN_ID";
        public const string PARAM_DON_VI_BAN_HANH = "@DON_VI_BAN_HANH";
        public const string PARAM_TRICH_YEU = "@TRICH_YEU";
        public const string PARAM_DUONG_DAN_FILE = "@DUONG_DAN_FILE";
        public const string PARAM_NGUOI_TAO = "@NGUOI_TAO";
        public const string PARAM_NGUOI_SUA = "@NGUOI_SUA";
        public const string PARAM_DON_VI_TRUY_CAP = "@DON_VI_TRUY_CAP";


        public bool Save(ShareFile model)
        {
            try
            {
                SqlCommand cmd = this.GetSprocCommand(PROCEDURE_INSERT);
                cmd.Parameters.Add(CreateParameter(PARAM_SO_VAN_BAN, model.SO_VAN_BAN));
                cmd.Parameters.Add(CreateParameter(PARAM_DON_VI_BAN_HANH, model.DON_VI_BAN_HANH));
                cmd.Parameters.Add(CreateParameter(PARAM_TRICH_YEU, model.TRICH_YEU));
                cmd.Parameters.Add(CreateParameter(PARAM_DUONG_DAN_FILE, model.DUONG_DAN_FILE));
                cmd.Parameters.Add(CreateParameter(PARAM_NGUOI_TAO, model.NGAY_TAO));
                int result = ExecuteNonQuery(cmd);

                return result > 0 ? true : false;
            }
            catch
            {
                throw;
            }
        }
        public bool Update(ShareFile model)
        {
            try
            {
                SqlCommand cmd = this.GetSprocCommand(PROCEDURE_UPDATE);
                cmd.Parameters.Add(CreateParameter(PARAM_VAN_BAN_ID, model.VAN_BAN_ID));
                cmd.Parameters.Add(CreateParameter(PARAM_SO_VAN_BAN, model.SO_VAN_BAN));
                cmd.Parameters.Add(CreateParameter(PARAM_DON_VI_BAN_HANH, model.DON_VI_BAN_HANH));
                cmd.Parameters.Add(CreateParameter(PARAM_TRICH_YEU, model.TRICH_YEU));
                cmd.Parameters.Add(CreateParameter(PARAM_DUONG_DAN_FILE, model.DUONG_DAN_FILE));
                cmd.Parameters.Add(CreateParameter(PARAM_NGUOI_SUA, model.NGAY_TAO));
                cmd.Parameters.Add(CreateParameter(PARAM_DELETED, model.DELETED));
                int result = ExecuteNonQuery(cmd);

                return result > 0 ? true : false;
            }
            catch
            {
                throw;
            }
        }
        public List<ShareFile> GetallbyDonviID(int donvibanhanh)
        {
            try
            {
                SqlCommand cmd = this.GetSprocCommand(PROCEDURE_SEARCH_BY_DON_VI);
                cmd.Parameters.Add(CreateParameter(PARAM_DON_VI_BAN_HANH, donvibanhanh));
                return GetList<ShareFile>(cmd);
            }
            catch
            {
                throw;
            }
        }
        public List<ShareFile> GetallbyDonviTruyCap(int donvitruycap)
        {
            try
            {
                SqlCommand cmd = this.GetSprocCommand(PROCEDURE_SEARCH_BY_DON_VI_TRUY_CAP);
                cmd.Parameters.Add(CreateParameter(PARAM_DON_VI_TRUY_CAP, donvitruycap));
                return GetList<ShareFile>(cmd);
            }
            catch
            {
                throw;
            }
        }
        public List<ShareFile> GetallbyID(int id) {
            try
            {
                SqlCommand cmd = this.GetSprocCommand(PROCEDURE_SEARCH_BY_ID);
                cmd.Parameters.Add(CreateParameter(PARAM_VAN_BAN_ID, id));
                return GetList<ShareFile>(cmd);
            }
            catch
            {
                throw;
            }
        }

    }
}
